﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using PMSGSC.BLL;
using PMSGSC.DAL;
using PMSGSC.Common;

namespace PMSGSC.App
{
    public partial class frmFilterHistory : DevExpress.XtraEditors.XtraForm
    {
        public frmFilterHistory(frmMain objMain)
        {
            InitializeComponent();
            employeeBindingSource.DataSource = Employee_BLL.GetAll(frmMain.ship.Ship_ID);
            deFrom.DateTime = DateTime.Now.Date.AddMonths(-1);
            deTo.DateTime = DateTime.Now.Date;
            main = objMain;
        }
        private frmMain main;
        private void btnOK_Click(object sender, EventArgs e)
        {
            frmProcessBar pb = new frmProcessBar();
            System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
            {
                LoadSkinToForm();
                pb.ShowDialog();
            }
            ));
            thread.Start();

            int equipID = 0, workOrderID = 0, JobID = 0;
            if (ucLoadEquipment1.lbid.Text != "")
                equipID = int.Parse(ucLoadEquipment1.lbid.Text);

            if (ucLoadJobDescription1.lbid.Text != "")
                JobID = int.Parse(ucLoadJobDescription1.lbid.Text);

            if (ucLoadWorkOrder1.lbid.Text != "")
                workOrderID = int.Parse(ucLoadWorkOrder1.lbid.Text);

            List<History> histories = History_BLL.FilterHistory(equipID, workOrderID, JobID, gleReportBy.Text,
                deFrom.DateTime.Date, deTo.DateTime.Date,frmMain.ship.Ship_ID);
           
            if (histories.Count != 0)
            {
                frmHistoryDetail historyDetail = new frmHistoryDetail(histories);
                historyDetail.MdiParent = main;
                historyDetail.Show();
                if (pb.InvokeRequired)
                {
                    pb.BeginInvoke(new Action(() => pb.Close()));
                }
                this.Close();
            }
            else
            {
                if (pb.InvokeRequired)
                {
                    pb.BeginInvoke(new Action(() => pb.Close()));
                }  
                XtraMessageBox.Show("Not result show on display", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private static void LoadSkinToForm()
        {
            DevExpress.Skins.SkinManager.EnableFormSkins();
            DevExpress.UserSkins.BonusSkins.Register();
            DevExpress.UserSkins.OfficeSkins.Register();
            DevExpress.LookAndFeel.DefaultLookAndFeel obj = new DevExpress.LookAndFeel.DefaultLookAndFeel();
            try
            {
                LookAndFeelSettings.Load("LookAndFeelSettings.dat");
            }
            catch
            {
                obj.LookAndFeel.SetSkinStyle("Blue");
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            ucLoadEquipment1.SetValue("", "", "");
            ucLoadJobDescription1.SetValue("", "", "");
            ucLoadWorkOrder1.SetValue("", "", "");
            gleReportBy.EditValue = null;
        }
    }
}